package com.slz3.business.module.systemManagement.sysRoleMenu.steward;

import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.response.ResInfo;
import com.slz3.business.module.systemManagement.sysRoleMenu.domain.SysRoleMenu;
import com.slz3.business.module.systemManagement.sysRoleMenu.domain.SysRoleMenuCondition;
import org.springframework.stereotype.Controller;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;
import java.util.Optional;
import java.util.UUID;

public class SysRoleMenuResController extends SysRoleMenuResAtomic {

    public Mono<ServerResponse> add(ServerRequest req, SysRoleMenu sysRoleMenu) {
        if (SysRoleMenuResUnsafeValid.add(req, sysRoleMenu)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.add_$SysRoleMenuUpdateLock(req, sysRoleMenu);
        }
    }

    public Mono<ServerResponse> info(ServerRequest req) {
        Optional<String> roleUuid = req.queryParam("roleUuid");
        Optional<String> menuUuid = req.queryParam("menuUuid");
        if (!roleUuid.isPresent() || !menuUuid.isPresent()) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        }
        SysRoleMenu sysRoleMenu = Services.sysRoleMenu.info(UUID.fromString(roleUuid.get()), UUID.fromString(menuUuid.get()));
        return RR.success(req, ResInfo.builder().code(RR.SUCCESS).domain(sysRoleMenu).build());
    }

}
